import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.sql.*;

public class GUIUtil {

    public static String selectFile( ) {
	 return selectFile("Text files", "txt");
    }

    public static String selectFile(String desc, String type ) {

	// Use JFileChooser object to select CDF file to process.
	JFileChooser chooser = new JFileChooser (System.getProperty("user.dir") +
			System.getProperty( "file.separator") + "data") ;
	FileNameExtensionFilter filter = new FileNameExtensionFilter(desc, type);
	chooser.setFileFilter(filter);
	int res = chooser.showOpenDialog( null );

	// If a file is selected, save the selected in member variable.
	if ( res == JFileChooser.APPROVE_OPTION)
		return chooser.getSelectedFile().getPath(); // Save CDF file  

	return null;
    }

    public static void fillComboBox( ResultSet res, JComboBox cbx ) {
	 fillComboBox( res, 1, cbx );
    }

    public static void fillComboBox( ResultSet res, int colNum, JComboBox cbx ) {
	try {
		while ( res.next() ) cbx.addItem( res.getString(colNum ) );
	} catch (SQLException e) { e.printStackTrace(); }
    }


}

